import React, { useState } from 'react'
import { Button } from 'react-vant';
import { ActionSheet, Cell, Area } from 'react-vant'
import { areaList } from '@vant/area-data';
import {useDispatch,useSelector} from 'react-redux'
import {LOGNIT} from '../../types/store.d'
interface CHSE {
  code: string,
  name: string
}

export default function registry() {
  const dispatch = useDispatch()
  const [visible, setVisible] = useState(false);
  const onCancel = () => setVisible(false);
  const [value] = useState('330302');
  const handleClicAss = () => {
    setVisible(true)
  }
  const hanEnsure = (val: CHSE[]) => {

    let adress = ''
    val.forEach((item => {
      adress += item.name + ''
    }))
    dispatch({
      type:LOGNIT,
      payload:adress
    })
    setVisible(false)
  }
  return (
    <div>
      <Button type="primary" onClick={() => handleClicAss()}>点击添加地址</Button>


      <Cell title="自定义面板" isLink onClick={() => setVisible(true)} />
      <ActionSheet visible={visible} onCancel={onCancel}>
        <div style={{ padding: '16px 16px 160px' }}>
          <Area
            title="选择收货地址"
            areaList={areaList}
            value={value}
            onChange={(v) => console.log(v)}
            onConfirm={(v) => hanEnsure(v)}
          />
        </div>
      </ActionSheet>
    </div>
  )
}
